// https://leetcode.cn/problems/bitwise-and-of-numbers-range/
// Created by ade on 2022/8/26.
//
#include <iostream>
#include <vector>

using namespace std;

// 这题的本质在于求公共前缀
class Solution {
public:
    int rangeBitwiseAnd(int left, int right) {
        int n = 0;
        while (left != right) {
            left >>= 1;
            right >>= 1;
            n++;
        }
        return left << n;
    }
};

int main() {
    Solution so;
    cout << so.rangeBitwiseAnd(1, 2147483647);
    return 0;
}